<?php

namespace App\Admin\Controllers;

use App\UserList;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\InfoBox;

class UserListController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
//    protected $title = '用户管理';
    public function index(Content $content)
    {
        return $content
            ->header('用户管理')
            ->description('')
            ->row(function ($row){
                $row->column( 6, new InfoBox('总用户量', 'book', 'blue', '', UserList::count()));
                $row->column( 6, new InfoBox('今日新增', 'book', 'green', '', UserList::whereDate('created_at',date('Y-m-d'))->count()));
            })
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserList);
        $grid->actions(function ($actions) {
            // 去掉查看
            $actions->disableView();
            $actions->disableEdit();
        });
        $grid->model()->orderBy('id','desc');
        $grid->column('id', 'id')->sortable();
        $grid->column('min_openid', 'openID');
        $grid->column('created_at','创建时间');
        $grid->column('updated_at', '更新时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {

    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new UserList);
        $form->text('username', '用户昵称');
        //$form->image('avatar', '用户头像')->uniqueName()->removable();
        return $form;
    }
}
